package com.csdj.course.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * 请求处理之前的过滤器
 */
@Component
public class PreRequestFilter extends ZuulFilter {
    @Override
    public String filterType() {
        //过滤器的类型
        return FilterConstants.PRE_TYPE;
    }
    @Override
    public int filterOrder() {
        return 0; //过滤器的顺序
    }
    @Override
    public boolean shouldFilter() {
        //是否启用过滤器
        return true;
    }
    @Override
    public Object run() throws ZuulException {
        //核心业务代码
        RequestContext context=RequestContext.getCurrentContext();
        context.set("startTime",System.currentTimeMillis());
        System.out.println("过滤器已经记录时间：");
        return null;
    }
}